package com.example.yf.service.impl;

import com.example.yf.mapper.YFMapper;
import com.example.yf.pojo.YFPOJO;
import com.example.yf.result.Result;
import com.example.yf.service.YFService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class YFServiceImpl implements YFService {

    @Autowired
    private YFMapper yfMapper;

    @Override
    public Result ComputeBMR(YFPOJO yfpojo) {
        if (yfpojo.getYfWeight() == null || yfpojo.getYfHeight() == null || yfpojo.getYfAge() == null || yfpojo.getYfSex() == null) {
            return Result.error(201,"参数错误");
        }
        //计算基础代谢公式
        if (yfpojo.getYfSex().equals("男")) {
            yfpojo.setYfBmr((int) (66 + 13.7 * yfpojo.getYfWeight() + 5 * yfpojo.getYfHeight() - 6.8 * yfpojo.getYfAge()));
        } else {//计算女性的基础代谢
            yfpojo.setYfBmr((int) (655 + 9.6 * yfpojo.getYfWeight() + 1.8 * yfpojo.getYfHeight() - 4.7 * yfpojo.getYfAge()));
        }
        if (yfpojo.getYfBmr() > 0) {
            yfMapper.insertUserBmr(yfpojo);
            return Result.SUCCESS();
        }
        //拿到这个用户基础代谢后，判断他的身高体重和性别，然后推断出它是较胖还是较瘦

        return null;
    }
}
